<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="/include/taglibs.jsp" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<html>
<head>
    <%@include file="/include/header.html" %>
    <link rel="stylesheet" href="${ctx}/libjs/plugins/h-ui/css/H-ui.admin.css">
    <link rel="stylesheet" href="${ctx}/libjs/plugins/h-ui/style.css">
    <%--<script src="${ctx}/libjs/jquery.min.js"></script>--%>
    <%--<script src="${ctx}/libjs/bootstrap.js"></script>--%>
    <script type="text/javascript" src="${ctx}/libjs/plugins/bootstrap/js/bootstrap-select.js"></script>
    <link rel="stylesheet" type="text/css" href="${ctx}/libjs/plugins/bootstrap/css/bootstrap-select.css">
    <link href="http://libs.baidu.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet">
    <%--<script src="http://libs.baidu.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>--%>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
<%--    <script type="text/javascript"--%>
<%--            src="https://webapi.amap.com/maps?v=1.3&key=e392de55be62b195115e32b97043a1bd&plugin=AMap.Autocomplete,AMap.PlaceSearch"></script>--%>
    <script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=d8f0f46fc7446a9bed5a28cdc5aaeb52&plugin=AMap.Autocomplete,AMap.PlaceSearch"></script>
    <script type="text/javascript" src="${ctx}/appjs/elec/elecStation.js"></script>
</head>

<script type="text/javascript">
    $('#topLink', window.parent.document).html(function (i, origText) {
        return '<ol class="breadcrumb">' +
            '<li class="breadcrumb-item">' +
            '<a href="">主页</a>' +
            '</li>' +
            '<li class="breadcrumb-item">' +
            '<a>设备管理</a>' +
            '</li>' +
            '<li class="breadcrumb-item">' +
            '<strong>编辑桩群</strong>' +
            '</li>' +
            '<li class="breadcrumb-item">' +
            '<a href="javascript:window.history.back()"><i class="fa fa-times"></i> 返回</a>' +
            '</li>' +
            '</ol>';
    });

    $(window).on('load', function () {
        $('.selectpicker').selectpicker({
            'selectedText': 'cat'
        });
        // $('.selectpicker').selectpicker('hide');
    });

</script>

<body class="gray-bg">
<div class="wrapper wrapper-content ">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <div class="columns pull-left">
                        <h5 class="font-bold">编辑充电站</h5>
                    </div>
                    <div class="ibox-tools">
                        <a class="close-link">
                            <i class="fa fa-times"></i>
                        </a>
                    </div>
                </div>

                <div class="ibox-content">
                    <form class="form-horizontal m-t" id="frmElecStation">
                        <input id="elecStationId" name="elecStationId" value="${elecStation.elecStationId}"
                               type="hidden">
                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">充电站编号：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" id="stationNo" name="stationNo" readonly
                                       value="${elecStation.stationNo}">
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">充电站名称：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" id="stationName" name="stationName"
                                       value="${elecStation.stationName}">
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">站点类型：</label>
                            <div class="col-sm-8">
                                <select class="form-control" name="bizType" id="bizType">
                                    <option value="0"
                                            <c:if test="${elecStation.bizType eq '0'}">selected</c:if> >自营
                                    </option>
                                    <option value="1"
                                            <c:if test="${elecStation.bizType eq '1'}">selected</c:if> >加盟
                                    </option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">所属加盟商：</label>
                            <div class="col-sm-8">
                                <select name="operatorId" id="operatorId" class="form-control">
                                    <c:forEach items="${operators}" var="operatorInfo">
                                        <option value="${operatorInfo.operatorId}"
                                                <c:if test="${operatorInfo.operatorId == elecStation.operatorId}">selected</c:if>
                                        >${operatorInfo.operatorName}</option>
                                    </c:forEach>
                                </select>
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">省-市-区：</label>
                            <div class="col-sm-2">
                                <select name="provinceId" id="provinceId"
                                        class="form-control chosen-select"
                                        style="width: 100%" onchange="station.getCity()">
                                    <option value="" selected="selected">--请选择--</option>
                                    <c:forEach items="${provinces}" var="province">
                                        <option value="${province.provinceId}"
                                                <c:if test="${province.provinceId eq elecStation.provinceId}">selected</c:if>  >${province.provinceName}</option>
                                    </c:forEach>
                                </select>
                            </div>

                            <div class="col-sm-2">
                                <select name="cityId" id="cityId"
                                        class="form-control chosen-select"
                                        style="width: 100%" onchange="station.getArea()">
                                    <option value="${elecStation.cityId}"
                                            selected="selected">${elecStation.cityName}</option>
                                </select>
                            </div>

                            <div class="col-sm-2">
                                <select id="areaId" name="areaId" class="form-control" placeholder="市区">
                                    <option value="${elecStation.areaId}"
                                            selected="selected">${elecStation.areaName}</option>
                                </select>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">地址详情：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" id="address" name="address"
                                       value="${elecStation.address}">
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">纬度：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" id="latitude" name="latitude"
                                       value="${elecStation.latitude}">
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">经度：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" id="longitude" name="longitude"
                                       value="${elecStation.longitude}">
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">地图：</label>
                            <div class="col-sm-8">
                                <button id="id_address_input" type="button" class="btn btn-info " onclick="showMap()">
                                    开启地图
                                </button>
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">站点当前状态：</label>
                            <div class="col-sm-8">
                                <select class="form-control" id="stationStaus" name="stationStaus">
                                    <option value="0" ${elecStation.stationStaus=="0"?"selected":""}>停用</option>
                                    <option value="1" ${elecStation.stationStaus=="1"?"selected":""}>正常</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">投运时间：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" id="operateStartTime" name="operateStartTime"
                                       value="${elecStation.operateStartDate}">
                            </div>
                        </div>
                        <%--<div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">标签：</label>
                            <div class="col-sm-8">
                                <select name="stationFlag" id="stationFlag" class="form-control">
                                    <c:forEach items="${labels}" var="labelInfo">
                                        <option value="${labelInfo.labelId}"
                                                &lt;%&ndash;<c:if test="${elecStation.stationFlag== labelInfo.labelId}">selected</c:if>&ndash;%&gt;
                                                <c:if test="${fn:contains(elecStation.stationFlag,labelInfo.labelId )}">selected</c:if>
                                        >${labelInfo.labelName}</option>
                                    </c:forEach>
                                </select>
                            </div>
                        </div>--%>
                        <div class="form-group row  istam">
                            <label class="col-sm-3 col-form-label text-right">多选标签：</label>
                            <select id="labelIds" name="labelIds" class="selectpicker bla bla bli" multiple data-live-search="true">
                                <c:forEach items="${labels}" var="labelInfo">
                                    <option value="${labelInfo.labelId}"
                                        <%--<c:if test="${elecStation.stationFlag== labelInfo.labelId}">selected</c:if>--%>
                                            <%--<c:if test="${fn:contains('elecStation.stationFlag',labelInfo.labelId )}">selected</c:if>--%>
                                            <c:if test="${fn:contains(elecStation.labelIds,labelInfo.labelId )}">selected</c:if>
                                    >${labelInfo.labelName}</option>
                                </c:forEach>
                            </select>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">备注说明：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" id="stationRemark" name="stationRemark"
                                       value="${elecStation.stationRemark}">
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">图片1：</label>
                            <div class="col-sm-8">
                                <div id="">
                                    <c:choose>
                                        <c:when test="${elecStation.stationImg1!=null && elecStation.stationImg1!=''}">
                                            <div id="">
                                                <img id="stationImg1" src="${uploadPath}${elecStation.stationImg1}"
                                                     width="155px" height="120px">
                                                <input type="file" id="file1" name="file1"/>
                                            </div>
                                        </c:when>
                                        <c:otherwise>
                                            <div id="">
                                                <img id="stationImg1" src="${ctx}/statics/img/upload-img.png"
                                                     style="position: relative" width="155px" height="120px">
                                                <input type="file" id="file1" name="file1"/>
                                            </div>
                                        </c:otherwise>
                                    </c:choose>
                                </div>
                                <span>图片尺寸建议为：<span class="text-danger">98px*75px</span></span>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">图片2：</label>
                            <div class="col-sm-8">
                                <div id="">
                                    <c:choose>
                                        <c:when test="${elecStation.stationImg2!=null && elecStation.stationImg2!=''}">
                                            <div id="">
                                                <img id="stationImg2" src="${uploadPath}${elecStation.stationImg2}"
                                                     width="155px" height="120px">
                                                <input type="file" id="file2" name="file2"/>
                                            </div>
                                        </c:when>
                                        <c:otherwise>
                                            <div id="">
                                                <img id="stationImg2" src="${ctx}/statics/img/upload-img.png"
                                                     style="position: relative" width="155px" height="120px">
                                                <input type="file" id="file2" name="file2"/>
                                            </div>
                                        </c:otherwise>
                                    </c:choose>
                                </div>
                                <span>图片尺寸建议为：<span class="text-danger">98px*75px</span></span>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">图片3：</label>
                            <div class="col-sm-8">
                                <div id="">
                                    <c:choose>
                                        <c:when test="${elecStation.stationImg3!=null && elecStation.stationImg3!=''}">
                                            <div id="">
                                                <img id="stationImg3" src="${uploadPath}${elecStation.stationImg3}"
                                                     width="155px" height="120px">
                                                <input type="file" id="file3" name="file3"/>
                                            </div>
                                        </c:when>
                                        <c:otherwise>
                                            <div id="">
                                                <img id="stationImg3" src="${ctx}/statics/img/upload-img.png"
                                                     style="position: relative" width="155px" height="120px">
                                                <input type="file" id="file3" name="file3"/>
                                            </div>
                                        </c:otherwise>
                                    </c:choose>
                                </div>
                                <span>图片尺寸建议为：<span class="text-danger">98px*75px</span></span>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">图片4：</label>
                            <div class="col-sm-8">
                                <div id="">
                                    <c:choose>
                                        <c:when test="${elecStation.stationImg4!=null && elecStation.stationImg4!=''}">
                                            <div id="">
                                                <img id="stationImg4" src="${uploadPath}${elecStation.stationImg4}"
                                                     width="155px" height="120px">
                                                <input type="file" id="file4" name="file4"/>
                                            </div>
                                        </c:when>
                                        <c:otherwise>
                                            <div id="">
                                                <img id="stationImg4" src="${ctx}/statics/img/upload-img.png"
                                                     style="position: relative" width="155px" height="120px">
                                                <input type="file" id="file4" name="file4"/>
                                            </div>
                                        </c:otherwise>
                                    </c:choose>
                                </div>
                                <span>图片尺寸建议为：<span class="text-danger">98px*75px</span></span>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">图片5：</label>
                            <div class="col-sm-8">
                                <div id="">
                                    <c:choose>
                                        <c:when test="${elecStation.stationImg5!=null && elecStation.stationImg5!=''}">
                                            <div id="">
                                                <img id="stationImg5" src="${uploadPath}${elecStation.stationImg5}"
                                                     width="155px" height="120px">
                                                <input type="file" id="file5" name="file5"/>
                                            </div>
                                        </c:when>
                                        <c:otherwise>
                                            <div id="">
                                                <img id="stationImg5" src="${ctx}/statics/img/upload-img.png"
                                                     style="position: relative" width="155px" height="120px">
                                                <input type="file" id="file5" name="file5"/>
                                            </div>
                                        </c:otherwise>
                                    </c:choose>
                                </div>
                                <span>图片尺寸建议为：<span class="text-danger">98px*75px</span></span>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-3 col-sm-offset-8 text-right">
                                <button type="submit" class="btn btn-primary">提交</button>
                                <%--<button type="button" onclick="checkSize()">11111</button>--%>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="modal fade modal1" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog modalBox" style="height: 80%;width: 100%">
        <div class="modal-content" style="height: 100%">
            <div class="modal-header">
                <%--<button type="button" class="close" data-dismiss="modal" aria-hidden="true">--%>
                <%--&times;--%>
                <%--</button>--%>
                <h4 class="modal-title" id="myModalLabel">
                    请点击地图选择坐标
                </h4>
            </div>
            <div class="modal-body" style="height: 80%">
                <div id="containerMap"></div>
                <div id="myPageTop">
                    <table>
                        <tr>
                            <td>
                                <label>按关键字搜索：</label>
                            </td>
                            <td class="column2">
                                <label>左击获取经纬度：</label>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <input type="text" style="color: #000" placeholder="请输入关键字进行搜索" id="tipinput">
                            </td>
                            <td class="column2">
                                <input type="text" readonly="true" id="lnglat">
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                </button>
                <button type="button" class="btn btn-primary" id="confirmMap">
                    提交更改
                </button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
<script type="text/javascript">


    /*时间控件begin*/
    layui.use('laydate', function () {
        var laydate = layui.laydate;
        var bizStartTime = laydate.render({
            elem: '#bizStartTime',
            type: 'time',
            format: 'HH:mm:ss',
            trigger: 'click'
        });

        var bizEndTime = laydate.render({
            elem: '#bizEndTime',
            type: 'time',
            format: 'HH:mm:ss',
            trigger: 'click'
        });

        var operateStartTime = laydate.render({
            elem: '#operateStartTime',
            type: 'date',
            format: 'yyyy-MM-dd',
            trigger: 'click'
        });
    });

    /*时间控件end*/
    // function checkSize() {
    //     var totalSize = 0;
    //     $("input[type='file']").each(function () {
    //         console.log($(this))
    //         if($(this)[0].files.length==1){
    //                 totalSize +=$(this)[].files[0].size;
    //                 if(totalSize>10485760){
    //                     layer.msg('请上传少于1M的图片');
    //                     return
    //                 }
    //             console.log($(this)[0].files[0].size)
    //         }
    //         // var objUrl = getObjectURL($(this).files[0]);//获取文件信息
    //         // if(objUrl){
    //         //     totalSize +=$(this).files[0].size;
    //         //     if(totalSize>10485760){
    //         //         layer.msg('请上传少于1M的图片');
    //         //         return
    //         //     }
    //         // }
    //     })
    // }

    /**************************/
    $("#file1").change(function () {
        var objUrl = getObjectURL(this.files[0]);//获取文件信息
        var fileSize = $(this)[0].files[0].size
        if (objUrl) {
            if (fileSize > (2 * 1024 * 1024)) {
                layer.msg('请上传小于2M的图片！');
                $(this).val("");
                return
            }
            $("#stationImg1").attr("src", objUrl);
        }
    });

    $("#file2").change(function () {
        var objUrl = getObjectURL(this.files[0]);//获取文件信息
        var fileSize = $(this)[0].files[0].size
        if (objUrl) {
            if (fileSize > (2 * 1024 * 1024)) {
                layer.msg('请上传小于2M的图片！');
                $(this).val("");
                return
            }
            $("#stationImg2").attr("src", objUrl);
        }
    });

    $("#file3").change(function () {
        var objUrl = getObjectURL(this.files[0]);//获取文件信息
        var fileSize = $(this)[0].files[0].size
        if (objUrl) {
            if (fileSize > (2 * 1024 * 1024)) {
                layer.msg('请上传小于2M的图片！');
                $(this).val("");
                return
            }
            $("#stationImg3").attr("src", objUrl);
        }
    });

    $("#file4").change(function () {
        var objUrl = getObjectURL(this.files[0]);//获取文件信息
        var fileSize = $(this)[0].files[0].size
        if (objUrl) {
            if (fileSize > (2 * 1024 * 1024)) {
                layer.msg('请上传小于2M的图片！');
                $(this).val("");
                return
            }
            $("#stationImg4").attr("src", objUrl);
        }
    });

    $("#file5").change(function () {
        var objUrl = getObjectURL(this.files[0]);//获取文件信息
        var fileSize = $(this)[0].files[0].size
        if (objUrl) {
            if (fileSize > (2 * 1024 * 1024)) {
                layer.msg('请上传小于2M的图片！');
                $(this).val("");
                return
            }
            $("#stationImg5").attr("src", objUrl);
        }
    });

    function getObjectURL(file) {
        var url = null;
        if (window.createObjectURL != undefined) {
            url = window.createObjectURL(file);
        } else if (window.URL != undefined) { // mozilla(firefox)
            url = window.URL.createObjectURL(file);
        } else if (window.webkitURL != undefined) { // webkit or chrome
            url = window.webkitURL.createObjectURL(file);
        }
        return url;
    }

    /*************************/


    addElecStation.init();
</script>
</body>
</html>
<script>
    //地图
    function showMap() {
        $('#myModal').modal('show')
        var map = new AMap.Map("containerMap", {
            resizeEnable: true,
            zoom: 11,
        });
        map.plugin(["AMap.ToolBar"], function () {
            map.addControl(new AMap.ToolBar());
        });
        if (location.href.indexOf('&guide=1') !== -1) {
            map.setStatus({scrollWheel: false})
        }
        //为地图注册click事件获取鼠标点击出的经纬度坐标
        var clickEventListener = map.on('click', function (e) {
            document.getElementById("lnglat").value = e.lnglat.getLng() + ',' + e.lnglat.getLat();
            $('#lnglat').attr({
                'data-longitude': e.lnglat.getLng(),
                'data-latitude': e.lnglat.getLat()
            })
        });
        var auto = new AMap.Autocomplete({
            input: "tipinput"
        });
        var placeSearch = new AMap.PlaceSearch({
            map: map
        });  //构造地点查询类
        AMap.event.addListener(auto, "select", select);//注册监听，当选中某条记录时会触发
        function select(e) {
            if (e.poi && e.poi.location) {
                map.setZoom(15);
                map.setCenter(e.poi.location);
            }
            placeSearch.setCity(e.poi.adcode);
            placeSearch.search(e.poi.name);
        }


    }

    $('#myModal').on('click', '#confirmMap', function () {
        var longitude = $('#lnglat').attr('data-longitude');
        var latitude = $('#lnglat').attr('data-latitude');
        if (!longitude && !latitude) {
            layer.msg('请点击地图选择经纬度！');
            return
        }
        $('#longitude').val(longitude);
        $('#latitude').val(latitude);
        $('#myModal').modal('hide')
    });

</script>
